home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
The World of Computer Software.iso
/
newmarch.zip
/
HELLO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-08
|
4KB
|
164 lines
/* Author: $Author: jan $
* File: $Source: /usr/usrs/jan/desktop/X_Book.boo/programs/RCS/hello.c,v $
* Date: $Date: 1992/09/09 00:10:01 $
* Revision: $Revision: 1.1 $
*/
#include "copyright.h"
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
/*
** Constants
*/
char WINDOW_NAME[] = "Window";
char ICON_NAME[] = "Icon";
/*
** Globals
*/
Display *display; /* the display device */
int screen; /* the screen on the display */
Window main_window;
GC gc;
unsigned long foreground, background;
void
initX ()
{
/* set the display name from the environment
vbl DISPLAY */
display = XOpenDisplay (NULL);
if (display == NULL)
{ fprintf (stderr, "Unable to open display %s\n",
XDisplayName (NULL));
exit (1);
}
screen = DefaultScreen (display);
/* use the default foreground
and background colors */
foreground = BlackPixel (display, screen);
background = WhitePixel (display, screen);
}
/*
** Opens a window on the display device, and returns
** the window ID.
**
** It takes (x,y) coords, the width and height of the
** window, and the width of the border
*/
Window
openWindow (x, y, width, height,
border_width, argc, argv)
int x, y; /* coords of the upper left
corner in pixels */
int width, height; /* size of the window
in pixels */
int border_width; /* the border width is not
included in the
other dimensions */
int argc;
char **argv;
{
Window new_window;
XSizeHints size_hints;
/* now create the window */
new_window = XCreateSimpleWindow (display,
DefaultRootWindow (display),
x, y, width, height,
border_width,
foreground, background);
/* set up the size hints for the window manager */
size_hints.x = x;
size_hints.y = y;
size_hints.width = width;
size_hints.height = height;
/* and state what hints are included */
size_hints.flags = PPosition | PSize;
/* let the window manager know about the window */
XSetStandardProperties (display, new_window,
WINDOW_NAME, ICON_NAME,
None, /* no icon map */
argv, argc, &size_hints);
/* Return the window ID */
return (new_window);
}
/*
** Create a graphics context using default values, and
** return it in the pointer gc
*/
GC
getGC ()
{ GC gc;
XGCValues gcValues;
gc = XCreateGC (display, main_window,
(unsigned long) 0, &gcValues);
XSetBackground (display, gc, background);
XSetForeground (display, gc, foreground);
return (gc);
}
/*
** Terminate the program gracefully
*/
quitX ()
{
XCloseDisplay (display);
exit (0);
}
/*
** Write a string
** and draw a circle
*/
display_something ()
{ /* Ignore these three lines for now */
XEvent event;
XSelectInput (display, main_window, ExposureMask);
XNextEvent (display, &event);
/* end of ignore lines */
/* the proverbial string */
XDrawImageString (display, main_window, gc,
10, 10, "Hello world",
strlen ("Hello world"));
/* and a world (circle) to go with it */
XDrawArc (display, main_window, gc,
30, 30,
100, 100,
0, 360*64);
XFlush (display);
}
main (argc, argv)
int argc;
char **argv;
{
initX ();
main_window = openWindow (10, 20, 500, 400,
5, argc, argv);
gc = getGC ();
/* Display the window on the screen */
XMapWindow (display, main_window);
display_something ();
sleep (30);
quitX ();
}